/*
 * 文 件 名:  ActionMethod.java
 * 版    权:  Chrhc Technologies Co., Ltd. Copyright 2015-2099,  All rights reserved
 * 描    述:  <描述>
 * 修 改 人: 姓名 xxx
 * 修改时间:  2016年4月20日
 */
package com.struts;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <一句话功能简述> <功能详细描述>
 * 
 * @author 姓名 xxx
 * @version [1.0, 2016年4月20日]
 */
public class ActionMethod implements Action
{
    
    /**
     * 重载方法
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response)
    {
        String cmd = request.getParameter("cmd");
        if (cmd != null)
        {
            Class[] pTypes = new Class[] {ActionForm.class, HttpServletRequest.class, HttpServletResponse.class};
            Method method = null;
            try
            {
                method = this.getClass().getDeclaredMethod(cmd, pTypes);
            }
            catch (NoSuchMethodException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (SecurityException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Object[] objs = new Object[] {form, request, response};
            try
            {
                String forward = (String)method.invoke(this, objs);
                return mapping.findForward(forward);
            }
            catch (IllegalAccessException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (IllegalArgumentException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (InvocationTargetException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            this.getClass().getDeclaredMethods();
        }
        return null;
    }
    
    /**
     * <一句话功能简述> <功能详细描述>
     * 
     * @param args
     */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        
    }
    
}
